package com.example.oa.controller;

import com.example.oa.dto.ApproveApprovalProcessDTO;
import com.example.oa.dto.CreateApprovalProcessDTO;
import com.example.oa.dto.QueryApprovalProcessDTO;
import com.example.oa.dto.SubmitApprovalProcessDTO;
import com.example.oa.entity.ApprovalProcessDO;
import com.example.oa.response.RestResult;
import com.example.oa.service.ApprovalProcessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * OA流程流转Controller
 * </p>
 * @author 34448
 */
@Api(tags = "OA流程流转")
@RequestMapping("/approval")
@RestController
public class ApprovalProcessController {

    @Autowired
    private ApprovalProcessService approvalProcessService;

    /**
     * 创建审批流程
     *
     * @param createDTO 创建审批流程DTO
     * @return
     */
    @PostMapping("/create")
    @ApiOperation("创建审批流程")
    public RestResult<Boolean> createApprovalProcess(@Valid @RequestBody CreateApprovalProcessDTO createDTO) {
        Boolean result = approvalProcessService.createApprovalProcess(createDTO);
        return new RestResult<>(HttpStatus.OK.value() + "", "调用成功", result);
    }

    /**
     * 提交审批流程
     *
     * @param submitDTO 提交审批流程DTO
     * @return
     */
    @PostMapping("/submit")
    @ApiOperation("提交审批流程")
    public RestResult<Boolean> submitApprovalProcess(@Valid @RequestBody SubmitApprovalProcessDTO submitDTO) {
        Boolean result = approvalProcessService.submitApprovalProcess(submitDTO);
        return new RestResult<>(HttpStatus.OK.value() + "", "调用成功", result);
    }

    /**
     * 审批流程
     *
     * @param approveDTO 审批流程DTO
     * @return
     */
    @PostMapping("/approve")
    @ApiOperation("审批流程")
    public RestResult<Boolean> approveApprovalProcess(@Valid @RequestBody ApproveApprovalProcessDTO approveDTO) {
        Boolean result = approvalProcessService.approveApprovalProcess(approveDTO);
        return new RestResult<>(HttpStatus.OK.value() + "", "调用成功", result);
    }

    /**
     * 查询审批流程
     *
     * @param queryDTO 查询审批流程DTO
     * @return
     */
    @GetMapping("/query")
    @ApiOperation("查询审批流程")
    public RestResult<List<ApprovalProcessDO>> queryApprovalProcesses(@Validated QueryApprovalProcessDTO queryDTO) {
        List<ApprovalProcessDO> result = approvalProcessService.queryApprovalProcesses(queryDTO);
        return new RestResult<>(HttpStatus.OK.value() + "", "调用成功", result);
    }

    /**
     * 删除审批流程
     *
     * @param processId 流程ID
     * @return
     */
    @DeleteMapping("/delete/{processId}")
    @ApiOperation("删除审批流程")
    public RestResult<Boolean> deleteApprovalProcess(@PathVariable Integer processId) {
        Boolean result = approvalProcessService.deleteApprovalProcess(processId);
        return new RestResult<>(HttpStatus.OK.value() + "", "调用成功", result);
    }
}